package com.heifeng.cloudshelf.mvp.programme.provider;

import android.content.Context;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.heifeng.cloudshelf.R;
import com.heifeng.cloudshelf.mvp.model.ProgrammeSelectInfo;
import com.heifeng.cloudshelf.mvp.model.SpecMultipleEntity;
import com.heifeng.cloudshelf.mvp.programme.adapter.DialogSpecTextRvAdapter;
import com.heifeng.cloudshelf.mvp.programme.adapter.SpecMultipleItemRvAdapter;

import java.util.List;

/**
 * Created by admin on 2019/9/19.
 */

public class DialogSpecItemProvider extends BaseItemProvider<SpecMultipleEntity, BaseViewHolder> {
    private List<ProgrammeSelectInfo> infos;

    private GridLayoutManager gridLayoutManager;

    private DialogSpecTextRvAdapter adapter;

    public DialogSpecItemProvider(Context context, List<ProgrammeSelectInfo> infos) {
        this.infos = infos;
        mContext = context;
    }

    @Override
    public int viewType() {
        return SpecMultipleItemRvAdapter.TYPE_VIEW_DIALOG;
    }

    @Override
    public int layout() {
        return R.layout.layout_spec_item;
    }

    @Override
    public void convert(BaseViewHolder helper, SpecMultipleEntity data, int position) {
        helper.setImageResource(R.id.iv_icon, infos.get(data.getPosition()).getIcon());
        helper.setText(R.id.tv_title, infos.get(data.getPosition()).getTitle());
        initRecyclerView(helper.getView(R.id.recyclerview), data);
    }

    public void initRecyclerView(RecyclerView recyclerView, SpecMultipleEntity data) {
        gridLayoutManager = new GridLayoutManager(mContext, 9);
        recyclerView.setLayoutManager(gridLayoutManager);
        adapter = new DialogSpecTextRvAdapter(mContext, R.layout.layout_spec_dialog_string_item, infos.get(data.getPosition()).getOptions(), infos);
        recyclerView.setAdapter(adapter);
    }


}
